package com.kgc.scd.controller;


import com.kgc.scd.bean.Order;
import com.kgc.scd.service.WebOrderService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created On : 2022/11/15.
 * <p>
 * Author : #jiangguoqiang
 * <p>
 * Description: OrderComtroller
 */
@RestController
@Slf4j
@Api(tags = "订单入口")
public class WebOrderComtroller {
    @Autowired
    private WebOrderService webOrderService;

    /**
     *  快递下单发货
     */
    @PostMapping("/orderExpress")
    @ApiOperation(value = "快递下单发货",notes = "快递下单发货")
    public RequestResult<String> orderExpress(@ApiParam(name = "orderNo",value = "订单号")@RequestParam String orderNo){
        return webOrderService.orderExpress(orderNo);
    }

    /**
     * @author : Administrator
     * @date   : 2022/11/17
     * @param  : [LogisticCode, orderNo]
     * @return : com.kgc.scd.util.RequestResult<java.util.Map<java.lang.String,java.lang.Object>>
     * @description : 快递查询
     */
    @PostMapping("/selectExpress")
    @ApiOperation(value = "查询物流",notes = "物流状态")
    public RequestResult<Map<String,Object>> selectExpress(@ApiParam(name = "LogisticCode",value = "物流单号")@RequestParam String LogisticCode,
                                                           @ApiParam(name = "orderNo",value = "订单号")@RequestParam String orderNo) {
        return webOrderService.selectExpress(LogisticCode,orderNo);
    }
    /**
     * @author : Administrator
     * @date   : 2022/11/15
     * @param  : [comment, pageNo, pageSize]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : 查询评论列表
     */
    @ApiOperation(value = "查询订单表",notes = "查询订单表")
    @GetMapping("/getOrderList")
    public RequestResult<PageSupport<Order>> getCommentList(@ApiParam(name = "orderGoodsId",value = "订单状态") @RequestParam(required = false) String orderGoodsId,
                                                            @ApiParam(required = true,name = "pageNo",value = "当前页") @RequestParam(value="pageNo",defaultValue="1") Integer pageNo,
                                                            @ApiParam(required = true,name = "pageSize",value = "条数") @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize){
        PageSupport<Order> support = webOrderService.getOrderList(orderGoodsId,pageNo,pageSize);

        return ResultBuildUtil.success(support);
    }


    /**
     * @author : Administrator
     * @date   : 2022/11/18
     * @param  : [id]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : 删除订单
     */
    @ApiOperation(value = "删除订单",notes = "根据订单状态删除订单")
    @GetMapping("/delOrderList")
    public RequestResult<?> delOrderList(String id){
        return webOrderService.delOrderList(id);
    }

    @GetMapping("/signOrderList")
    @ApiOperation(value = "签收订单",notes = "根据订单id来签收订单，将订单状态改为6")
    public RequestResult<?> signOrderList(@RequestParam String id){
        return webOrderService.signOrderList(id);
    }
}
